{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import socket \n",
    "\n",
    "client = socket.socket()\n",
    "host = socket.gethostname()\n",
    "port = 12345\n",
    "\n",
    "client.connect((host,port))\n",
    "print client.recv(1024)\n",
    "\n",
    "client.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import socket\n",
    "\n",
    "server = socket.socket()\n",
    "host = socket.gethostname()\n",
    "port = 12345\n",
    "\n",
    "server.bind((host,port))\n",
    "server.listen(5)\n",
    "while True:\n",
    "    c,addr = server.accept()\n",
    "    print '链接地址： ',addr\n",
    "    c.send('欢迎访问菜鸟教程')\n",
    "    c.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print 'Hello World'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
